//
//  NSString+VOCExtentions.m
//  iVoc
//
//  Created by Wallace Wu on 09-3-23.
//  Copyright 2009 Sonic Solutions. All rights reserved.
//

#import "NSString+VOCExtentions.h"

typedef struct int_trans_tab {
    NSUInteger key;
    NSString *string;
} TransTable;

TransTable functions[VOCWORDFunctionCount] = {
    {VOC_WORD_FUNC_NOUN,@"FUNC_NOUN"},
    {VOC_WORD_FUNC_VERB,@"FUNC_VERB"},
    {VOC_WORD_FUNC_ADJ, @"FUNC_ADJ"},
    {VOC_WORD_FUNC_ADV, @"FUNC_ADV"},
    {VOC_WORD_FUNC_PRON,@"FUNC_PRON"},
    {VOC_WORD_FUNC_CONJ,@"FUNC_CONJ"},
    {VOC_WORD_FUNC_PREP,@"FUNC_PREP"},
    {VOC_WORD_FUNC_INTE,@"FUNC_INTER"}
}; 

TransTable languages[VOCWORDLanguageCount] = {
    {VOC_WORD_LANG_ENGLISH, @"LANG_ENGLISH"},
    {VOC_WORD_LANG_SIMPCHI, @"LANG_SIMPCHI"}
};

@implementation NSString(VOCExtentions)

+(NSString*)stringRepOfFuntion:(VOCWORDFunction)aFunction
{
    NSMutableString *result = [[[NSMutableString alloc] init] autorelease];
    
    if(aFunction == VOC_WORD_FUNC_UNKNOWN)
    {
        [result appendString:NSLocalizedString(@"FUNC_UNKNOWN",nil)];
        return [[result copy] autorelease];
    }
    
    for (int i = 0; i < VOCWORDFunctionCount; i++) {
        if(aFunction & functions[i].key)
        {
            [result appendFormat:@"%@,", NSLocalizedString(functions[i].string,nil)];
        }
    }
    
    NSRange lastCharacter = NSMakeRange([result length]-1, 1);
    [result deleteCharactersInRange:lastCharacter];
    
    return [[result copy] autorelease];
}

+(NSString*)stringRepOfLanguage:(VOCWORDLanguage)aLanguage
{
    NSMutableString *result = [[[NSMutableString alloc] init] autorelease];
    
    if(aLanguage == VOC_WORD_LANG_UNKNOWN)
    {
        [result appendString:NSLocalizedString(@"LANG_UNKOWN",nil)];
        return [[result copy] autorelease];
    }
    
    for (int i = 0; i < VOCWORDLanguageCount; i++) {
        if(aLanguage & languages[i].key)
        {
            [result appendFormat:@"%@,", NSLocalizedString(languages[i].string,nil)];
        }
    }
    
    NSRange lastCharacter = NSMakeRange([result length]-1, 1);
    [result deleteCharactersInRange:lastCharacter];
    
    return [[result copy] autorelease];
}

@end
